package and.geo.matrix;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import and.awt.geom.AffineTransform;
import and.awt.geom.NoninvertibleTransformException;
import and.awt.geom.Point2D;
import and.awt.geom.Rectangle;

public class AffineViewport {
	private Rectangle screenArea;
	 private Envelope bounds;
	 private AffineTransform worldToScreen=null;
	 private final ReadWriteLock lock = new ReentrantReadWriteLock();
	public AffineViewport() {
		// TODO Auto-generated constructor stub
	}
	
	 /** Calculates the world bounds of the current screen area. */
    private Envelope calculateActualBounds() {
    	AffineTransform 	screenToWorld=null;
        Point2D p0 = new Point2D.Double(screenArea.getMinX(), screenArea.getMinY());
        Point2D p1 = new Point2D.Double(screenArea.getMaxX(), screenArea.getMaxY());
        screenToWorld = worldToScreen.createInverse();
        screenToWorld.transform(p0, p0);
        screenToWorld.transform(p1, p1);

        return new Envelope(
                Math.min(p0.getX(), p1.getX()),
                Math.max(p0.getX(), p1.getX()),
                Math.min(p0.getY(), p1.getY()),
                Math.max(p0.getY(), p1.getY())
               );
    }

}
